package org.linys.dao.sale;

import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.linys.model.sale.Sale;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
@SuppressWarnings("unchecked")
@Repository
public class SaleDAO {

	private SqlSession sqlSession;
	@Autowired
	public void setSqlSession(SqlSession sqlSession) {
		this.sqlSession = sqlSession;
	}
	public int save(Sale sale) {
		return sqlSession.insert("SaleMapper.insert", sale);
	}
	public int update(Sale sale) {
		return sqlSession.update("SaleMapper.update", sale);
	}
	
	public Sale editP(Sale sale) {
		return (Sale) sqlSession.selectOne("SaleMapper.P_EditSale", sale);
	}
	
	public List<Sale> view(Sale sale, Integer start, Integer rows) {
		return sqlSession.selectList("SaleMapper.view", sale, new RowBounds(start,rows));
	}
	public int count(Sale sale) {
		return (Integer) sqlSession.selectOne("SaleMapper.count",sale);
	}
	public int deleteByID(Integer id) {
		return sqlSession.delete("SaleMapper.deleteByID", id);
	}
	public Sale getBySaleID(Integer saleID) {
		return (Sale) sqlSession.selectOne("SaleMapper.getBySaleID", saleID);
	}
	public int updateStatus(Sale sale) {
		return sqlSession.update("SaleMapper.updateStatus", sale);
	}
	public int validateCode(Sale sale) {
		return (Integer) sqlSession.selectOne("SaleMapper.validateCode",sale);
	}
}
